package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.regex.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ByOrdersMapper;
import com.ruoyi.system.domain.ByOrders;
import com.ruoyi.system.service.IByOrdersService;

/**
 * 订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-01
 */
@Service
public class ByOrdersServiceImpl implements IByOrdersService 
{
    @Autowired
    private ByOrdersMapper byOrdersMapper;

    /**
     * 查询订单
     * 
     * @param id 订单主键
     * @return 订单
     */
    @Override
    public ByOrders selectByOrdersById(String id)
    {
        return byOrdersMapper.selectByOrdersById(id);
    }

    /**
     * 查询订单列表
     * 
     * @param byOrders 订单
     * @return 订单
     */
    @Override
    public List<ByOrders> selectByOrdersList(ByOrders byOrders)
    {
        List<ByOrders> orders = byOrdersMapper.selectByOrdersList(byOrders);
        for(ByOrders orders1:orders){
            String id = orders1.getStandardId();
            String result = removeTags(id);
            orders1.setStandardId(result);
        }
        return orders;
    }

    // 匹配HTML标签的正则表达式
    private static final Pattern HTML_TAG_PATTERN = Pattern.compile("<[^>]+>");

    public static String removeTags(String htmlContent) {
        if (htmlContent == null || htmlContent.isEmpty()) {
            return "";
        }
        // 替换所有匹配的标签为空白
        return HTML_TAG_PATTERN.matcher(htmlContent).replaceAll("");
    }

    /**
     * 新增订单
     * 
     * @param byOrders 订单
     * @return 结果
     */
    @Override
    public int insertByOrders(ByOrders byOrders)
    {
        return byOrdersMapper.insertByOrders(byOrders);
    }

    /**
     * 修改订单
     * 
     * @param byOrders 订单
     * @return 结果
     */
    @Override
    public int updateByOrders(ByOrders byOrders)
    {
        return byOrdersMapper.updateByOrders(byOrders);
    }

    /**
     * 批量删除订单
     * 
     * @param ids 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deleteByOrdersByIds(String[] ids)
    {
        return byOrdersMapper.deleteByOrdersByIds(ids);
    }

    /**
     * 删除订单信息
     * 
     * @param id 订单主键
     * @return 结果
     */
    @Override
    public int deleteByOrdersById(String id)
    {
        return byOrdersMapper.deleteByOrdersById(id);
    }

    @Override
    public String totalPaid(String beginTime,String endTime) {
        return byOrdersMapper.totalPaid(beginTime,endTime);
    }
}
